<template>
	<view class="myPublishNeeds">
		<view class="list">
			<view class="item" v-for="(item,i) in list" :key="i">
				<view class="item_l">
					<view class="">
						<view class="needs_name">需要兑换泌豆数</view>
						<view class="needs_val">{{item.money}}</view>
					</view>
					<view class="" style="padding: 28upx 0;">
						<view class="needs_name">可兑换贡献值数量</view>
						<view class="needs_val">{{item.option_num}}</view>
					</view>
					<view class="">
						<view class="needs_name">联系方式</view>
						<view class="needs_val">{{item.phone}}</view>
					</view>
				</view>
				<view class="item_r" @click="handleDelete(item.id)">
					<image src="https://wx.2024csnl.com/static/mine/del_icon.png" mode=""></image>
				</view>
			</view>
		</view>
		<view class="flex-center addressImgBox" v-if="list.length==0">
			<image src="https://wx.2024csnl.com/static/noData.png"></image>
			暂无数据~
		</view>
		<view style="text-align: center;color: #999;" v-if="noMoreData&&list.length!=0">没有更多啦~</view>
	</view>
</template>

<script>
	import {
		myPositionsRelease,
		delMyPositionsRelease
	} from "../../../api/index.js"
	export default {
		data() {
			return {
				list: [],
				pagenum:1,
				noMoreData:false,
			};
		},
		onLoad() {
			this.getMyPositionsRelease()
		},
		onReachBottom() {
			this.pagenum += 1
			this.getMyPositionsRelease('bottom')
		},
		methods: {
			// 删除
			async handleDelete(id) {
				const result = await new Promise(resolve => {
					uni.showModal({
						title: '提示',
						content: '确认删除该需求吗?',
						confirmColor: '#41644A',
						success(msg) {
							resolve(msg)
						}
					});
				})
				if (result.confirm) {
				
					const res = await delMyPositionsRelease('s=/ApiZwyRequest/needdelete', {
						id: id
					})
					const {
						status,
						msg
					} = res.data
					this.showToast(msg)
					if (status == 1) {
						setTimeout(()=>{
								this.pagenum = 1
							this.getMyPositionsRelease()
						},1500)
					}
				}
			},

			async getMyPositionsRelease(type) {
				const res = await myPositionsRelease(`s=/ApiZwyRequest/myneedlist&pagenum=${this.pagenum}`)
				const {
					data,
					status,
					msg
				} = res.data
				// console.log(res, "帮")
				if (status == 1) {
					type == 'bottom' ? this.list.push(...data) : this.list = data
					this.pagenum != 1 && data.length == 0 ? this.noMoreData = true : this.noMoreData = false
				} else {
					this.showToast(msg)
				}
			}
		}


	}
</script>

<style lang="scss">
	page {
		background-color: #f7f7f7;
	}

	.addressImgBox {
		flex-direction: column;
		color: #999;
		padding-top: 20%;

		image {
			width: 400rpx;
			height: 400rpx;
		}
	}

	.myPublishNeeds {
		padding-top: 4upx;

		.list {
			background-color: #fff;

			.item {
				display: flex;
				justify-content: space-between;
				padding: 34upx 40upx 40upx 32upx;
				box-sizing: border-box;
				border-top: 1upx solid #f7f7f7;

				.item_l {
					>view {
						display: flex;
						align-items: center;
						font-size: 28upx;
						line-height: 28upx;
						font-weight: 400;

						.needs_val {
							color: #41644A;
							margin-left: 20upx;
						}
					}
				}

				.item_r {
					image {
						width: 36upx;
						height: 34upx;
					}
				}
			}
		}
	}
</style>
